package com.cskaoyan.service.wx;

import com.cskaoyan.bean.FeedBack;
import com.cskaoyan.bean.User;
import com.cskaoyan.mapper.FeedBackMapper;
import com.cskaoyan.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author pengyehua
 * @date 2020/12/8 22:03
 */
@Service
public class WxFeedbackServiceImpl implements WxFeedbackService{

    @Autowired
    UserMapper userMapper;
    @Autowired
    FeedBackMapper feedBackMapper;


    private final int RELATED_GOODS = 1;//商品相关
    private final int FUNCTION_EXCEPTION = 2;//功能异常
    private final int OPTIMIZATION_SUGGESTION = 3;//优化建议
    private final int OTHER = 4;//其他

    /**
     * 插入反馈问题
     * @param feedBack
     * @param name
     */
    @Override
    public void submitFeedback(FeedBack feedBack, String name) {
        User user = userMapper.selectUserByName(name);
        Date date = new Date();
        feedBack.setAddTime(date);
        feedBack.setUpdateTime(date);
        feedBack.setDeleted(false);
        feedBack.setUserId(user.getId());
        feedBack.setUsername(name);
        //根据反馈类型获取对应的状态码
        int status;
        if(feedBack.getFeedType().equals("商品相关")){
            status = RELATED_GOODS;
        }else if(feedBack.getFeedType().equals("功能异常")){
            status = FUNCTION_EXCEPTION;
        }else if(feedBack.getFeedType().equals("优化建议")){
            status = OPTIMIZATION_SUGGESTION;
        }else{
            status = OTHER;
        }
        feedBack.setStatus(status);
        feedBackMapper.insert(feedBack);
    }
}
